import { UPDATEPAGEMYRESUME } from '../types/pagemyresume'
import { createAction } from 'redux-actions'
import { getArchiveInfoRequest, getZhichuUserInfoByAuth } from '../../../../service/user-info-controller'
import { getUserArchiveInfoRequest } from '../../../../service/user-archive-controller'

import formatdata from '../../../../util/pagemethods/userArchInfo'

export const DOREQUESTMYRESUME = createAction(UPDATEPAGEMYRESUME, payload => {
  return new Promise(resolve => {
    Promise.all([
      getUserArchiveInfoRequest({ ...payload }),
      getArchiveInfoRequest({ ...payload }),
      getZhichuUserInfoByAuth({ userId: payload.userId })
    ]).then(([{ data }, { data: { entry: { jobStatus } } }, { data: datain }]) => {
      const userInfo = {
        ...datain.entry,
        jobStatus
      }
      const { networkerror, entry, status, message } = data
      if (networkerror) {
        resolve({
          networkerror: true
        })
      } else {
        let Formatdata = new formatdata(entry || {}, userInfo, '')
        let dataformat = Formatdata.getFormatData()
        let wantWork = entry && entry.archive && entry.archive.jobHuntingModels || []
        resolve({
          networkerror: false,
          showEmpty: false,
          ...dataformat,
          wantWork
        })
      }
    })
  })
})
